package com.pbxadmin.service;

import java.net.URL;

import org.codehaus.xfire.client.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pbxadmin.cfg.PbxConfig;

@Service
public class PbxWebService{
	@Autowired
	PbxConfig pbxConfig;
	
	private Logger log = LoggerFactory.getLogger(PbxWebService.class);
	
	public String invokePbx(String method, Object ... args) {
		String result = "";
		try {
			Client client = new Client(new URL(pbxConfig.getPbxUrl()));
			Object[] results = client.invoke(method, args);
			result = String.valueOf(results[0]);
		}catch (Exception e) {
			log.error("调用PBX服务出错:{}",e.getMessage());
			e.printStackTrace();
		}finally{
			log.debug("PbxWebService--method:{},result:{}",method,result);
		}
		return result;
	}
}
